package com.lisx.module_add_new_word.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.lisx.module_add_new_word.R;
import com.lisx.module_add_new_word.bean.WordBean;

import java.util.ArrayList;
import java.util.List;

public class GkAdapter extends RecyclerView.Adapter<GkAdapter.VideoHolder> {

    private List<WordBean> mList;
    private Context mcontext;

    private OnItemClickLitener mOnItemClickLitener;


    //定义点击接口
    public interface OnItemClickLitener {
        void onItemClick(int position);
    }

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    public GkAdapter(Context mcontext, List<WordBean> mList) {
        this.mcontext = mcontext;
        this.mList = mList;

    }

    @Override
    public VideoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gk, parent, false);
        return new VideoHolder(itemView);

    }

    @Override
    public void onBindViewHolder(final VideoHolder holder, final int position) {
        int select = mList.get(position).getSelect();
        if (select == 1){
            holder.tv_gk.setVisibility(View.VISIBLE);
            holder.im_gk.setVisibility(View.GONE);
        }else {
            holder.tv_gk.setVisibility(View.GONE);
            holder.im_gk.setVisibility(View.VISIBLE);
        }
        holder.tv_gk.setText(""+mList.get(position).getId());
        holder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class VideoHolder extends RecyclerView.ViewHolder {


        private LinearLayout layout;
        private TextView tv_gk;
        private ImageView im_gk;


        VideoHolder(View itemView) {
            super(itemView);
            layout = itemView.findViewById(R.id.layout_gk);
            tv_gk = itemView.findViewById(R.id.tv_gk);
            im_gk = itemView.findViewById(R.id.im_gk);
        }
    }
}